package com.mnsq.message.controller;

import com.mnsq.common.bean.annotation.UserInfoRequired;
import com.mnsq.common.bean.conf.ThreadLocalUserId;
import com.mnsq.common.bean.entity.message.Message;
import com.mnsq.common.controller.BaseController;
import com.mnsq.common.service.BaseService;
import com.mnsq.message.bean.condition.MessageCondition;
import com.mnsq.message.bean.enums.MessageType;
import matrix.module.common.bean.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author 周俭
 */
@RestController
@RequestMapping("/api/message/")
public class MessageController extends BaseController<Message, BaseService<Message, MessageCondition>, MessageCondition> {

    /**
     * 发送信息
     *
     * @param t
     * @return
     */
    @UserInfoRequired(required = true)
    @Override
    public Result add(@RequestBody Message t) {
        t.setSenderUserId(ThreadLocalUserId.CURRENT_USER_ID.get());
        t.setType(MessageType.MSG_PER.code);
        t.setWhetherRead(MessageType.READ_NULL.code);
        return super.add(t);
    }

    /**
     * 查询个人收到的信息
     *
     * @param c
     * @return
     */
    @UserInfoRequired(required = true)
    @Override
    public Result queryPage(@RequestBody MessageCondition c) {
        c.setTargetUserId(ThreadLocalUserId.CURRENT_USER_ID.get());
        if (!c.valid()) {
            return Result.fail("请求参数错误");
        }
        return super.queryPage(c);
    }

    /**
     * 查询个人发出的信息
     *
     * @param c
     * @return
     */
    @PostMapping("/send/page")
    @UserInfoRequired(required = true)
    public Result querySendPage(@RequestBody MessageCondition c) {
        c.setSenderUserId(ThreadLocalUserId.CURRENT_USER_ID.get());
        if (!c.valid()) {
            return Result.fail("请求参数错误");
        }
        return super.queryPage(c);
    }

    @Override
    public Result queryListAll(@RequestBody MessageCondition c) {
        return Result.fail("暂不支持此功能");
    }

    @Override
    public Result update(@RequestBody Message t) {
        return Result.fail("暂不支持此功能");
    }
}
